package com.ldc.security.handle;

import com.ldc.common.constants.ConstantsCodeStatus;
import com.ldc.common.utils.ResponseUtils;
import com.ldc.model.utils.ResultUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 无权限
 *
 * @auther liudc
 * @since 2022/11/6
 */
@Component
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseUtils.toResult(response, ResultUtils.toFailed("无权限，请联系管理员～", ConstantsCodeStatus.PERMISSION_DENIAL_CODE));
    }
}
